package me.zk.practice1.hw;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author zhangkai
 * @date 2023/8/7 17:14
 */
public class HWBJ68 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String s = scanner.nextLine();

        List<List<String>> list = new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
            String s1 = s.substring(0,i);
            String s2 = s.substring(i,s.length());
            if (get(s1) && get(s2)) {
                List<String> l = new ArrayList<>();
                l.add(s1);
                l.add(s2);
                list.add(l);
            }

        }
        if (list.size() != 1) {
            System.out.println(-1);
        } else {
           System.out.println(list.get(0).size());
        }

    }

    public static boolean get(String s) {

        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            count+= s.charAt(i);
        }
        if (count > 999 || count<100) {
            return false;
        }
        int a = count/100;
        int b = count/10%10;
        int c = count%100%10;
        return count == (int)(Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3));
    }

}
